//-------------------Sonic CD Logo Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.Value0 : Object.Fade

// States
#alias 0	:	LOGO_WHITE_FADEIN
#alias 1	:	LOGO_SONIC_ANIMATE
#alias 2	:	LOGO_SONIC_RESET

// Callbacks & Engine States
#alias 7	:	CALLBACK_EXIT_SELECTED

#alias 2	:	TEXTINFO_ROWCOUNT // Menu Alias


sub ObjectDraw
	TempValue0 = Screen.CenterX
	TempValue0 <<= 1
	DrawSpriteScreenXY(16, 0, 100)
	DrawSpriteScreenXY(17, TempValue0, 100)
	
	switch Object.State
	case LOGO_WHITE_FADEIN
		SetScreenFade(255, 255, 255, Object.Fade)
		
		// Draw boths halves of the Emblem
		Object.Direction = FACING_RIGHT
		DrawSpriteScreenFX(0, FX_FLIP, Screen.CenterX, 40)
		
		Object.Direction = FACING_LEFT
		DrawSpriteScreenFX(0, FX_FLIP, Screen.CenterX, 40)
		
		// Draw Sonic
		DrawSpriteScreenXY(2, Screen.CenterX, 120)
		
		// Draw the Ribbon
		TempValue0 = Screen.CenterX
		TempValue0 -= 110
		DrawSpriteScreenXY(1, TempValue0, 135)
		
		// And draw his initial Arm frame too
		TempValue0 += 121
		DrawSpriteScreenXY(4, TempValue0, 110)
		
		if Object.Fade > 0
			Object.Fade -= 8
		else
			Object.State = LOGO_SONIC_ANIMATE
			Object.Frame = 4
		end if
		break

	case LOGO_SONIC_ANIMATE
		
		// Draw both ends of the Emblem
		Object.Direction = FACING_RIGHT
		DrawSpriteScreenFX(0, FX_FLIP, Screen.CenterX, 40)
		Object.Direction = FACING_LEFT
		DrawSpriteScreenFX(0, FX_FLIP, Screen.CenterX, 40)
		
		// Draw the main Sonic sprite
		DrawSpriteScreenXY(2, Screen.CenterX, 120)
		
		// If needed, draw his blinking frame
		if Object.Frame > 7
			if Object.Frame < 13
				TempValue0 = Screen.CenterX
				TempValue0 -= 43
				DrawSpriteScreenXY(3, TempValue0, 48)
			end if
		end if
		
		// Draw the ribbon ontop of that
		TempValue0 = Screen.CenterX
		TempValue0 -= 110
		DrawSpriteScreenXY(1, TempValue0, 135)
		
		// And afterwards, draw his arm
		TempValue0 += 121
		DrawSpriteScreenXY(Object.Frame, TempValue0, 110)
		
		Object.Fade++
		if Object.Fade > 1
			Object.Fade = 0
			Object.Frame++
			if Object.Frame > 15
				Object.State = LOGO_SONIC_RESET
				Object[+1].Type = TypeName[Touch Start]
				Object[+1].iXPos = Screen.CenterX
				Object[+1].iYPos = 200
			end if
		end if
		break

	case LOGO_SONIC_RESET
		Object.Direction = FACING_RIGHT
		DrawSpriteScreenFX(0, FX_FLIP, Screen.CenterX, 40)
		Object.Direction = FACING_LEFT
		DrawSpriteScreenFX(0, FX_FLIP, Screen.CenterX, 40)
		
		DrawSpriteScreenXY(2, Screen.CenterX, 120)
		
		TempValue0 = Screen.CenterX
		TempValue0 -= 110
		DrawSpriteScreenXY(1, TempValue0, 135)
		TempValue0 += 121
		DrawSpriteScreenXY(4, TempValue0, 110)
		break

	end switch
	
	// sure i guess?
	if Engine.PlatformID == RETRO_WP7
		if KeyPress[0].ButtonB == true
			EngineCallback(CALLBACK_EXIT_SELECTED)
		end if
	end if
	
end sub


sub ObjectStartup
	
	LoadSpriteSheet("Title/Title.gif")
	
	// 0 - Logo Ring
	SpriteFrame(-130, 0, 130, 152, 381, 73)
	
	// 1 - Logo Ribbon
	SpriteFrame(0, 0, 220, 80, 1, 122)
	
	// 2 - The man himself, Sonic!
	SpriteFrame(-47, -96, 104, 120, 1, 1)
	
	// 3 - Sonic's Eyes
	SpriteFrame(0, 0, 56, 48, 106, 33)
	
	// 4-15 - Sonic Arm Frames
	SpriteFrame(0, -38, 45, 55, 210, 203)
	SpriteFrame(0, -44, 32, 61, 223, 125)
	SpriteFrame(-1, -44, 25, 61, 230, 63)
	SpriteFrame(-10, -44, 30, 61, 225, 1)
	SpriteFrame(-1, -44, 25, 61, 230, 63)
	SpriteFrame(0, -44, 32, 61, 223, 125)
	SpriteFrame(0, -38, 45, 55, 210, 203)
	SpriteFrame(0, -44, 32, 61, 223, 125)
	SpriteFrame(-1, -44, 25, 61, 230, 63)
	SpriteFrame(-10, -44, 30, 61, 225, 1)
	SpriteFrame(-1, -44, 25, 61, 230, 63)
	SpriteFrame(0, -44, 32, 61, 223, 125)
	
	// 16 - Left Mountain Frame
	SpriteFrame(0, 0, 176, 68, 256, 4)
	
	// 17 - Right Mountain
	
	// This SpriteFrame differs across each version of the game
	// The Blit version had an issue where it didn't cover empty space when in widescreen, revealing a grey rectangle
	// The Mobile and Origins releases use a new sprite that's wider, with it getting even wider in a later mobile version
	
#platform: Use_Decomp
	// For the decomp, use the original Blit sprite regardless of version
	// The grey square is fixed via added code in the Background object's ObjectDraw sub
	SpriteFrame(-124, 0, 124, 68, 296, 267) 

#endplatform

#platform: Use_Standalone
	// SpriteFrame(-124, 0, 124, 68, 256, 77) // Blit version
	// SpriteFrame(-144, 0, 144, 68, 257, 251) // Older Mobile version
	SpriteFrame(-174, 0, 174, 68, 246, 267)	// Current Mobile version
#endplatform

#platform: Use_Origins
	SpriteFrame(-144, 0, 144, 68, 257, 251) // Origins version
#endplatform
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	Object.Direction = FACING_RIGHT
	DrawSpriteFX(0, FX_FLIP, Object.XPos, Object.YPos)
	Object.Direction = FACING_LEFT
	DrawSpriteFX(0, FX_FLIP, Object.XPos, Object.YPos)
end sub


sub RSDKLoad
	LoadSpriteSheet("Title/Title.gif")
	SpriteFrame(-130, 0, 130, 152, 381, 73)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub
